package com.gulimall.authserver.config;

import com.gulimall.authserver.constant.AutoServerConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class AutoConfigFactory {
    @Autowired
    private AutoGitConfigProperties autoGitConfigProperties;

    @Autowired
    private AutoWeiBoConfigProperties autoWeiBoConfigProperties;

    public Map<String, String> getPropertiesMap(AutoServerConstant.AutoType autoType) {
        Map<String, String> map = new HashMap<>();
        switch (autoType) {
            case WEIBO:
                map.put("client_id", autoWeiBoConfigProperties.getClientId());
                map.put("client_secret", autoWeiBoConfigProperties.getClientSecret());
                map.put("grant_type", autoWeiBoConfigProperties.getGrantType());
                map.put("redirect_uri", autoWeiBoConfigProperties.getRedirectUri());
                return map;
            case GITEE:
                map.put("client_id", autoGitConfigProperties.getClientId());
                map.put("client_secret", autoGitConfigProperties.getClientSecret());
                map.put("grant_type", autoGitConfigProperties.getGrantType());
                map.put("redirect_uri", autoGitConfigProperties.getRedirectUri());
                return map;
            default:
                return new HashMap<>();
        }
    }

    public AutoConfigProperties getProperties(AutoServerConstant.AutoType autoType) {
        switch (autoType) {
            case WEIBO:
                return autoWeiBoConfigProperties;
            case GITEE:
                return autoGitConfigProperties;
            default:
                return null;
        }
    }
}
